<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {
	
	

		
	public function index(){

		$config['upload_path'] = 'http://redwolf.cdf.toronto.edu:8830/ci/pics';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = '20000';
		$config['max_width'] = '1024';
		$config['max_height'] = '768';
			
		$this->load->library('upload',$config);
		$this->load->helper('form');
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->form_validation->set_rules('email','email','required');
		$this->form_validation->set_rules('email_conf','email_conf','required|matches[email]');
		$this->form_validation->set_rules('pwd','pwd','required');
		$this->form_validation->set_rules('pwd_conf','pwd_conf','required|matches[pwd]');
		
		if($this->form_validation->run() == FALSE || !$this->upload->data()){
			$data['page_title'] = 'failed';
			$this->load->view('register_view',$data);
			
	
		} else {
			$email = $this->input->post('email');
			$addr = $this->input->post('addr');
			$nickname = $this->input->post('Nname');
			$pwd = $this->input->post('pwd');
			$pic = $this->input->post('pic');
			$gender = $this->input->post('gender');
			$byear  = $this->input->post('year');
			$bmonth = $this->input->post('month');
			$bday = $this->input->post('day'); 
			$pn = $this->input->post('phone');
			$this->load->model('register_model');
			if(!$this->register_model->check_record($email)){
				$this->register_model->register_user($email, $addr, $nickname, $pwd, $pic,$gender,$pn,$byear,$bmonth,$bday);
				$this->session->set_userdata('logged_in', true);
				$this->session->set_userdata('user_id', $email);
				header("Location: http://redwolf.cdf.toronto.edu:8830/ci/index.php/main"); 
			}else{
			

			}
		}

	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>